package com.woniuxy.controller;

import com.woniuxy.dao.MerchantReturnCommentMapper;
import com.woniuxy.dto.DataGridView;
import com.woniuxy.dto.MyDto;
import com.woniuxy.feign.FeignOrder;
import com.woniuxy.pojo.MerchantReturnComment;
import com.woniuxy.pojo.PreOrder;
import com.woniuxy.pojo.User;
import com.woniuxy.service.TPerCommentservice;
import com.woniuxy.vo.TPerCommentVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class TPerCommentController {
    @Autowired
    private TPerCommentservice tPerCommentservice;
    @Autowired
    private MerchantReturnCommentMapper merchantReturnCommentMapper;
    @GetMapping("/findallcoments.do")
    @ResponseBody
    public DataGridView findAllcoments(TPerCommentVo tPerCommentVo){
        Subject subject= SecurityUtils.getSubject();
        Session session=subject.getSession();
        User user=(User)session.getAttribute("USER_SESSION");
        tPerCommentVo.setMerchantID(user.getId()+"");
        DataGridView res=tPerCommentservice.findAllcoments(tPerCommentVo);
        return res;
    }
    @PostMapping("/toreturncomment.do")
    @ResponseBody
    public MyDto toreturncomment(MerchantReturnComment merchantReturnComment){
        merchantReturnComment.setCreatetime(new Date());
        MyDto myDto =new MyDto();
        try{
            merchantReturnCommentMapper.insert(merchantReturnComment);
            myDto.setCode(200);
            myDto.setMsg("回复成功");
        }catch (Exception e){
            e.printStackTrace();
            myDto.setCode(-200);
            myDto.setMsg("回复失败");
        }
        return myDto;
    }

    @Autowired
     private FeignOrder feignOrder;
    @GetMapping("/test")
    @ResponseBody
    public MyDto test(){
        Map map=new HashMap();
        map.put("num","111134");
        Map z= feignOrder.order(map);
        System.out.println(z);
       return null;
    }
}
